<?php
require_once '../model/Seance.php';

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

class SeanceManager {
    private $bdd;
    private $listeSeance;
    
    function __construct($bdd) {
        $this->bdd = $bdd;
    }
    
    public function add(Seance $seance) {

        $q = $this->bdd->prepare('INSERT INTO SEANCES (idProjet, libelle, date) VALUES(:idProjet, :libelle, :date)');
        $q->bindValue(':idProjet', $seance->getIdProjet());
        $q->bindValue(':libelle', $seance->getLibelleSeance());
        $q->bindValue(':date', $seance->getDateSeance());
        $q->execute();
    }

    public function delete(Seance $seance) {
        $id = $seance->getIdSeance();
        $this->connexion();
        $bdd->exec('DELETE FROM SEANCES WHERE idProjet = ' . $id);
    }
    
    public function findSeance(Seance $seance){
        $q = $this->bdd->prepare('SELECT * FROM SEANCES WHERE idSeance = '. $seance->getIdSeance());
        $q->execute();
        $donnees = $q->fetchAll();
        return $donnees;
    }
    
    public function getListeSeance() {
        return $this->listeSeance;
    }

    public function setListeSeance() {

        $this->listeSeance=array();
                
        $q = $this->bdd->prepare('SELECT * FROM SEANCES');
        $q->execute();
        
        while ($data = $q->fetch()){

            $seance = new Seance($data["libelle"], $data["idSeance"],$data["idProjet"], $data["dateSeance"]);
            $this->listeSeance[]=$seance;
        }
    }

    
    public function getListSeance ($idProjet) {
        $listSeance = array();
        $req = $this->bdd->prepare('SELECT * FROM SEANCES WHERE idProjet='.$idProjet);
        $req->execute();
        while ($donnees = $req->fetch()) {
            $seance = new Seance($donnees["libelle"], $donnees["idSeance"],$donnees["idProjet"],$donnees["date"]);
            array_push($listSeance, $seance);
        }
        return $listSeance;
    }
    
     public function  getDate ($id) {
        $requete ="SELECT SEANCES.date FROM SEANCES WHERE SEANCES.idSeance=$id";
        $req = $this->bdd->prepare($requete);
        $req->execute();
        $donnees = $req->fetch();
      //  var_dump($donnees);
        $date =  $donnees['date'];
        //echo ucfirst($donnees["date"]);
        return $date;
    }

}
